package com.fgw.service.impl;

import com.fgw.common.ServerResponse;
import com.fgw.dao.TeacherMapper;
import com.fgw.pojo.Teacher;
import com.fgw.service.ITeacherlibService;
import com.fgw.vo.TeacherlibVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by lcx on 2017/9/13.
 */
@Service("iTeacherlibService")
public class TeacherlibServiceImpl implements ITeacherlibService {

    @Autowired
    private TeacherMapper teacherMapper;

    public ServerResponse<TeacherlibVo> getTeacherlibList() {

        //封装页面vo
        TeacherlibVo teacherlibVo = new TeacherlibVo();

        teacherlibVo.setTeacherList(teacherMapper.selectAllTeacher());

        return ServerResponse.createBySuccess(teacherlibVo);
    }

    /**
     * 师资登录serviceinpl
     * @param tuser
     * @param tpassword
     * @return
     */
    @Override
    public ServerResponse<Teacher> login(String tuser, String tpassword) {
        //检验
        int resultcheak=teacherMapper.ckeakTusername(tuser);
        if(resultcheak==0){
           return ServerResponse.createByErrorMessage("用户名不存在");
        }

        Teacher teacher=teacherMapper.selectTeacherLogin(tuser,tpassword);
        if(teacher==null){
           return ServerResponse.createByErrorMessage("用户名密码错误");
        }
        teacher.setTpassword(StringUtils.EMPTY);
        return ServerResponse.createBySuccess("登录成功",teacher);

    }

    /**
     * 后台分页查询师资库
     * @param pageNum
     * @param pageSize
     * @param c
     * @return
     */
    @Override
    public ServerResponse<PageInfo> getTeacherManagerList(Integer pageNum, Integer pageSize, char c) {

        PageHelper.startPage(pageNum,pageSize);

        List<Teacher> teacherList =teacherMapper.selectAllAdminTeacher();

        PageInfo pageReult=new PageInfo(teacherList);
        pageReult.setList(teacherList);

        return ServerResponse.createBySuccess(pageReult);
    }


}
